<template>
  <div class="header">
    <div class="left-fold" @click="collapseClick">
      <el-icon size="24">
        <Fold v-if="!isCollapse"/>
        <Expand v-else/>
      </el-icon>
    </div>
    <div class="right">
      <el-dropdown>
          <div class="user" style="margin-left: 24px">
              <el-avatar class="avatar" :size="32" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
              <el-icon>
                <ArrowDown />
              </el-icon>
          </div>
          <template #dropdown>
          <el-dropdown-menu>
        
              <el-dropdown-item divided @click="handleExitClick">
                  <el-icon>
                      <SwitchButton />
                  </el-icon>
                  退出登录
              </el-dropdown-item>
          </el-dropdown-menu>
          </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
// 注：defineProps、defineEmits在script setup顶层写法中都可以不导入直接使用
import { ArrowDown } from '@element-plus/icons-vue';
import { ref } from 'vue'
import { userStore } from '@/store/user'
const emits = defineEmits(['changeCollapse'])

const store = userStore()
const isCollapse = ref(false)
const collapseClick = () => {
  isCollapse.value = !isCollapse.value
  emits('changeCollapse', isCollapse.value)
}

const handleExitClick = () => {
  store.accountLogout()
}
</script>

<style scoped lang="less">
// header
.header {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 12%), 0 0 3px 0 rgb(0 0 0 / 4%);

  .left-fold {
    cursor: pointer;
  }
  .right {
    cursor: pointer;
    .avatar {
      margin-right: 5px;
    }
  }
}
// header end
</style>
